<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021/5/31
  Time: 17:33
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/common/common.jsp" %>
<html>
<head>
    <title>Title</title>
    <script>


        $(function () {
            $('#table').bootstrapTable({
                // /car/serverlist
                url: '<%=path%>/category/selectserver',
                method: 'post',                      //请求方式（*）
                contentType: "application/x-www-form-urlencoded",
                toolbar: '#for_div',              //工具按钮用哪个容器
                striped: true,                     //是否显示行间隔色
                cache: false, //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
                pagination: true,//是否显示分页（*）
                sortOrder: "desc",//排序方式
                sortName: "cid",//排序字段
                sidePagination: "server",//分页方式：client客户端分页，server服务端分页（*）
                pageNumber: 1,//初始化加载第一页，默认第一页,并记录
                pageSize: 3,//每页的记录行数（*）
                pageList: [1, 3, 5],//可供选择的每页的行数（*）
                // search: true,//是否显示表格搜索
                // strictSearch: true,//严格搜索
                showColumns: true,//是否显示所有的列（选择显示的列）
                showRefresh: true,//是否显示刷新按钮
                minimumCountColumns: 2,             //最少允许的列数
                clickToSelect: true,                //是否启用点击选中行
                uniqueId: "cid",                     //每一行的唯一标识，一般为主键列
                showToggle: true,                   //是否显示详细视图和列表视图的切换按钮
                // cardView: true,                    //是否显示详细视图
                detailView: true,                  //是否显示父子表
                //列
                queryParams: function (params) {
                    var temp = {
                        pageSize: params.limit,
                        pageNumber: (params.offset / params.limit) + 1,
                        //天条件查询
                        cname: $("#cname").val(),
                        roomid: $("[name=roomid]").val()
                    }
                    return temp;
                },
                columns: [{
                    checkbox: true,
                    visible: true                  //是否显示复选框
                }, {
                    field: 'cid',
                    title: 'ID'
                }, {
                    field: 'cname',
                    title: '名字'
                },
                    {
                        title: "操作",
                        //value daibiaozhi row 代表 数据 index 代表当前下表
                        formatter: function (value, row, index) {
                            var id = row.cid;
                            var result = "";
                            result += "<a href='javascript:toUpdate(" + id + ")' class='btn btn-xs blue' title='编辑'><span class='glyphicon glyphicon-pencil'></span></a>";
                            result += "<a href='javascript:deleteInfoById(" + id + ")' class='btn btn-xs red' title='删除'><span class='glyphicon glyphicon-remove'></span></a>";
                            return result;
                        }

                    },]

            });

        })

        function deleteInfoById(id) {
            alert(id)
            if (confirm("确认删除吗")) {

                $.ajax({
                    url: "<%=path%>/category/empdelete",
                    data: {id: id},
                    dataType: "json",
                    type: "post",
                    success: function (result) {
                        alert("删除成功");
                        $("#table").bootstrapTable("refresh");

                    },
                    error: function (result) {
                        console.log(result);
                        alert("网络异常请刷新");

                    }


                })
            }
        };


        function selectInfo() {
            $("#table").bootstrapTable("refresh");
        }

        function piliangshanchu() {
            var ids = [];
            //
            var rows = $("#table").bootstrapTable("getSelections");
            console.log(rows);
            $(rows).each(function (i, e) {
                ids.push(e.sid);
                alert(ids)

            })
            if (ids.length <= 0) {
                return;
            }
            $.ajax({
                url: "<%=path%>/category/deleteshanchu",
                type: "get",
                dataType: "json",
                data: {ids: ids},
                async: true,
                success: function (result) {

                    toastr.success("删除成功");
                    selectInfo();

                },
                error: function (result) {
                    toastr.error("网络异常")
                    console.log(result);
                }

            })
        }

        function toUpdate(id) {
            BootstrapDialog.show({
                title: '修改',
                message: $('<div></div>').load('<%=path%>/category/huixuan?cid=' + id),
                closeable: true,
                buttons: [{
                    label: '取消',
                    action: function (dialog) {
                        dialog.close();
                    }

                }, {
                    label: '确定',
                    action: function (dialog) {
                        $.ajax({
                            url: "<%=path%>/category/updateInfo",
                            type: "post",
                            dataType: "json",
                            data: $("#update_form").serialize(),
                            success: function (data) {
                                toastr.success("修改");
                                $("#table").bootstrapTable("refresh");
                            },
                            error: function (data) {
                                console.log(data);
                                alert("网络异常");
                            }

                        })

                    }
                }
                ]

            })
        }
        function insertInto() {
            BootstrapDialog.show({
                title: '增加',
                message: $('<div></div>').load('<%=path%>/category/insertInto'),
                closeable: true,
                buttons: [{
                    label: '取消',
                    action: function (dialog) {
                        dialog.close();
                    }

                }, {
                    label: '确定',
                    action: function (dialog) {
                        $.ajax({
                            url: "<%=path%>/category/insertADD",
                            type: "post",
                            dataType: "json",
                            data: $("#add_form").serialize(),
                            success: function (data) {

                                $("#table").bootstrapTable("refresh");
                                dialog.close();

                            },
                            error: function (data) {
                                console.log(data);
                                alert("网络异常");
                            }

                        })

                    }
                }
                ]

            })
        }


    </script>
</head>
<body>

<div id="for_div">
    <form class="form-inline" role="form">
        <div class="form-group">
            <label class="sr-only" for="cname">会议名称</label>
            <input type="text" class="form-control" id="cname" name="cname" placeholder="请输入名称">
        </div>
        <input type="button" class="btn btn-default" onclick="selectInfo()" value="提交">
        <input type="button" class="btn btn-danger" value="批量删除" onclick="piliangshanchu()">
        <input type="button" class="btn btn-default" value="增加" onclick="insertInto()">
    </form>
</div>
<table id="table"></table>
</body>
</html>
